var timeout         = 500;
var closetimer		= 0;
var ddmenuitem      = 0;
var jNum = 15; 

function mopen(id){	
	mcancelclosetime();
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
	ddmenuitem = document.getElementById(id);
	ddmenuitem.style.visibility = 'visible';
}

function mclose(){
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
}

function mclosetime(){
	closetimer = window.setTimeout(mclose, timeout);
}

function mcancelclosetime(){
	if(closetimer){
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}

function AddHistory(play_vid,playtit,infotit,infourl){
         var Str,ShowStr,iArr,TemStr,sArr,jArr;
         Str = getCookie("history");
         
         if(Str==null){
            Str = '';
         }
         
         if(typeof(play_vid)!="undefined"){
            var d = new Date();
            var years = d.getYear();
            var month = add_zero(d.getMonth()+1);
            var days = add_zero(d.getDate());
            var hours = add_zero(d.getHours());
            var minutes = add_zero(d.getMinutes());
            var seconds=add_zero(d.getSeconds());
            var ndate = month+"-"+days+" "+hours+":"+minutes+":"+seconds;
            if(playtit==''){
               playtit = "查看";
            }
            TemStr = play_vid+'$'+playtit+'$'+infotit+'$'+window.location.href+'$'+infourl+'$'+ndate+'$$';
            
            if(Str!=''){
              iArr = Str.split("$$");
              var n=0
              for(var i=0;i<iArr.length-1;i++){
                 if(play_vid-iArr[i].split("$")[0]!=0 && n<jNum){
                    TemStr += iArr[i]+'$$';
                    n++;
                 }
              } 
            }
            setCookie("history",TemStr,99999999);
         }
         
         ShowStr = getCookie("history");
         
         if(!ShowStr){
            ShowStr = '没有任何历史记录!';
         }else{
            sArr = ShowStr.split("$$");
            ShowStr = '';
            for(var i=0;i<sArr.length-1;i++){
               jArr = sArr[i].split("$");
               ShowStr += '<div class="his_list"><span class="ptime">'+jArr[5]+'</span><p><a class="del_his" href="javascript:;" onclick="DelHistory('+i+'); return false;" target="_self" title="删除本条记录"><a href="'+jArr[3]+'" class="infotit">'+jArr[1]+'</a><span><a href="'+jArr[4]+'">['+jArr[2]+']</a></span></p></div>';
            }
         }
         ShowStr = '<div class="clear_his"><a href="javascript:;" onclick="DelHistory(-1); return false;" target="_self">清空所有历史记录!</a></div>'+ShowStr;
         document.getElementById("history").innerHTML = ShowStr;
}

function DelHistory(i){
         var Str,iArr,TemStr;
         TemStr='';
         Str = getCookie("history");
         if(Str==null){
            Str = '';
         }
         if(i==-1){
           setCookie("history",null); 
         }else{
           iArr = Str.split("$$");
           for(var j=0;j<iArr.length-1;j++){
               if(j!=i){
                  TemStr += iArr[j]+'$$';
               } 
           }
         }
         setCookie("history",TemStr,99999999);
         AddHistory();
}

function add_zero(temp){
     if(temp<10){
        return "0"+temp;
     }else{
       return temp;
     }
}

function setTab(name,name2,cursel,n){
	 for(i=1;i<=n;i++){
	  var menu=document.getElementById(name+i);
	  var con=document.getElementById(name2+i);
	  menu.className=i==cursel?"current":"";
	  con.style.display=i==cursel?"block":"none";
	 }
}



var menu = $('#nav'),
pos = menu.offset();
$(window).scroll(function(){
	if($(this).scrollTop() > pos.top+menu.height() && menu.hasClass('nav')){
		menu.show('fast', function(){
			$(this).addClass('fixed').fadeIn('fast');
		});
	} else if($(this).scrollTop() <= pos.top && menu.hasClass('fixed')){
		menu.show('fast', function(){
			$(this).removeClass('fixed').fadeIn('500');
		});
	}
});

$(document).ready(function(){
	$("#back_top").hide();
	$(function () {
		$(window).scroll(function(){
		if ($(window).scrollTop()>100){
		$("#back_top").fadeIn(1500);
		}
		else
		{
		$("#back_top").fadeOut(1500);
		}
		});
		$("#back_top").click(function(){
		$('body,html').animate({scrollTop:0},1000);
		return false;
		});
		});
		});